package com.zhanglei.algorithm;

import com.zhanglei.method.Student;

/**
 * @author caesar
 * @date 2025/7/7
 * @Description: 冒泡排序
 *
 * @apiNote
 */

public class StudentBubbleSort {
    public static void main(String[] args) {
        Student[] students = new Student[3];

        students[0] = new Student("张三", 89);
        students[1] = new Student("李四",84);
        students[2] = new Student("王五",90);

        //冒泡排序：
        for(int i=1; i<students.length; i++){
            for(int j=0; j<students.length - i; j++){
                if(students[j].getScore() > students[j+1].getScore()){
                    Student temp = students[j];
                    students[j] = students[j+1];
                    students[j+1] = temp;
                }
            }
        }
        //显示排序后的结果
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i].display());
        }
    }
}
